package com.woniuxy.qiantai.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.dal.entity.Comment;
import com.woniuxy.dal.entity.Ranges;
import com.woniuxy.servicelayer.RangeService;
import com.woniuxy.servicelayer.vo.CommentVo;
import com.woniuxy.servicelayer.vo.DetailVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.sound.midi.Soundbank;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 靶场表(Range)表控制层
 *
 * @author makejava
 * @since 2023-03-27 22:21:38
 */
@RestController
@RequestMapping("range")
public class RangeController {
    /**
     * 服务对象
     */
    @Resource
    private RangeService rangeService;

    /**
     * 增加靶场
     */
    @RequestMapping("addRange")
    public String addRange(@RequestBody Ranges range){
        range.setCreateTime(LocalDate.now());
        int i = rangeService.addRange(range);
        return "okk";
    }

    /**
     * 删除靶场
     */
    @DeleteMapping("delRange/{id}")
    public String delRange(@PathVariable Integer id){
        int i = rangeService.delRange(id);
        return "okk";
    }

    /**
     * 修改靶场信息
     *
     * @return
     */
    @RequestMapping("updateRange")
    public String updateRange(@RequestBody Ranges range){
        rangeService.updateRange(range);
        return "okk";
    }

    /**
     * 查询靶场信息
     */
    @RequestMapping("selectRange")
    public Page<Ranges> selectRange(@RequestBody Map<String,Object> params){
        Object currentPage = params.get("currentPage");
        Object pageSize = params.get("pageSize");
        Object keyword = params.get("keyword");
        Object order = params.get("order");
        Object type = params.get("type");
        System.out.println("currentPage = " + currentPage);
        System.out.println("pageSize = " + pageSize);
        System.out.println("order = " + order);
        System.out.println("keyword = " + keyword);
        System.out.println("type = " + type);
        Page<Ranges> rangesPage = rangeService.selectRange((Integer) currentPage, (Integer) pageSize, (String) keyword, Integer.parseInt(order.toString()),(Integer) type);
        return rangesPage;
    }

    /**
     * 查询靶场信息
     */
    @RequestMapping("selectRangeCopy")
    public Page<Ranges> selectRangeCopy(@RequestBody Map<String,Object> params){
        Object currentPage = params.get("currentPage");
        Object pageSize = params.get("pageSize");
        Object keyword = params.get("keyword");
        Page<Ranges> rangesPage = rangeService.selectRangeCope((Integer) currentPage, (Integer) pageSize, (String) keyword);
        return rangesPage;
    }

    /**
     * 靶场分类查询
     */
    @RequestMapping("classificationQuery")
    public List<Ranges> classificationQuery(Integer typeId){
        return rangeService.classificationQuery(typeId);
    }

    @PostMapping("addVisitCount")
    public Integer addVisitCount(@RequestBody Map<String,String> params){
        Object rangeId = params.get("id");
        return rangeService.addVisitCount(rangeId);
    }

    @PostMapping("initDetailStats")
    public DetailVo initDetailStats(@RequestBody Map<String,String> params){
        Object rangeId = params.get("rangeId");
        String token = params.get("token");
        return rangeService.queryDetailStats(rangeId,token);
    }

    @PostMapping("fetchComments")
    public List<CommentVo> fetchComments(@RequestBody Map<String,Object> params){
        Object rangeId = params.get("rangeId");
        return rangeService.fetchComments(rangeId);
    }

    @PostMapping("sendComment")
    public void sendComment(@RequestBody Map<String,Object> params){
        Object rangeId = params.get("rangeId");
        Object token = params.get("token");
        Object comment = params.get("comment");
        rangeService.sendComment(rangeId,token,comment);
    }

//    @PostMapping("addTest")
//    public void addTest(@RequestBody Map<String,Object> params){
//        Object rangeId = params.get("rangeId");
//        Object token = params.get("token");
//        Object status = params.get("status");
//        rangeService.addTest(rangeId,token,status);
//    }

    @PostMapping("generateFlag")
    public String generateFlag(@RequestBody Map<String,Object> params){
        Object rangeId = params.get("rangeId");
        Object token = params.get("token");
        return rangeService.generateFlag(rangeId, (String) token);
    }

    @PostMapping("queryFlag")
    public Integer queryFlag(@RequestBody Map<String,Object> params){
        Object flag = params.get("flag");
        Object token = params.get("token");
        return rangeService.queryFlag(flag, (String) token);
    }


}




































